package JUnit;


import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import DAO.bookDAO;
import DAO.borrowDAO;
import HibernateUtilsforBM.SFactoryGenerator;
import HibernateUtilsforBM.forTestPool;
import Service.bookService;

public class TestDAO {
	//方法1 save 出现Field 'bookid' doesn't have a default value 原因：generator为native
	//方法2 delete 正常
	//方法3 findByName 少写一行设置parameter的代码
	//方法4 update设计上有点问题 更改了形参 先查询后更改的流程做了这次操作
	@Test
	public void bookTest(){
		forTestPool sf = new forTestPool();
		Session session = sf.getSession();
		Transaction transaction = session.beginTransaction();
		System.out.println(bookDAO.getBookNumber(session, 15));
		transaction.commit();
		session.close();
	}
	//方法1 save 添加用户 只允许普通用户
	//方法2 findByUsername 测试小问题 已修正
	//方法3 update 执行前先查找
	//方法4 查询后删除
	//方法5 用户名和密码查询用户
	@Test
	public void userTest(){
		SFactoryGenerator sf = new SFactoryGenerator();
		Session session = sf.getSession();
		Transaction transaction = session.beginTransaction();
		
		
		try{
			
		}catch(Exception e){
			e.printStackTrace();
			System.err.println("处理异常！");
			transaction.rollback();
		}
		session.close();
	}
	//方法1 方法2 都正常
	//方法3 设置参数语法错误
	@Test
	public void borrowTest(){
		forTestPool sf = new forTestPool();
		Session session = sf.getSession();
		Transaction transaction = session.beginTransaction();
		borrowDAO.removeRecord(session, 2, 1);
		
		transaction.commit();
		session.close();
	}
	//未测试
	@Test
	public void desctiptionTest(){
		SFactoryGenerator sf = new SFactoryGenerator();
		Session session = sf.getSession();
		Transaction transaction = session.beginTransaction();
		transaction.commit();
		session.close();
	}
	//service
	@Test
	public void testService(){
	}
	
}
